<!-- 任务-->

<template>
  <el-dialog
    :model-value="dialogFormVisible"
    :destroy-on-close="true"
    title="任务信息"
    width="450px"
    @close="emits('closeDialog')"
  >
    <el-form
      ref="dialogFormRef"
      :model="dialogForm"
      :rules="rules"
      :label-width="formLabelWidth"
    >
      <el-form-item label="名字" prop="name">
        <el-input v-model="dialogForm.name" />
      </el-form-item>
      <el-form-item label="描述" prop="description">
        <el-input v-model="dialogForm.description" />
      </el-form-item>
      <el-form-item label="奖励钻石" prop="diamond">
        <el-input v-model="dialogForm.diamond" />
      </el-form-item>
      <el-form-item label="跳转app页面名字" prop="go_name">
        <!-- <el-input v-model="dialogForm.go_name" /> -->
        <el-select v-model="dialogForm.go_name">
          <el-option
            v-for="item in bannerPageList"
            :key="item.id_name"
            :label="item.page_name"
            :value="item.id_name"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="跳转类型" prop="go_type">
        <el-select v-model="dialogForm.go_type" placeholder="跳转类型">
          <el-option label="go_app" value="go_app" />
          <el-option label="go_h5" value="go_h5" />
        </el-select>
      </el-form-item>
      <el-form-item label="跳转h5链接" prop="url">
        <el-input v-model="dialogForm.url" />
      </el-form-item>
      <el-form-item label="id" style="display: none">
        <el-input v-model="dialogForm.id" disabled />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="emits('cancel')">取消</el-button>
        <el-button
          type="primary"
          @click="submit(dialogForm)"
          :loading="btnLoading"
        >
          提交
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref } from "vue";
const dialogFormRef = ref(null);

defineProps({
  dialogFormVisible: {
    type: Boolean,
    default: false,
  },
  dialogForm: {
    type: Object,
    default: {
      id: "",
      name: "",
      description: "",
      diamond: "",
      go_name: "",
      go_type: "",
      url: "",
    },
  },
  btnLoading: {
    type: Boolean,
    default: false,
  },
  bannerPageList: {
    type: Array,
    default: [],
  },
});
const emits = defineEmits(["closeDialog", "cancel", "submitForm"]);

const formLabelWidth = "120px";
// 校验
const rules = {
  name: [{ required: true, message: "请输入名字", trigger: "blur" }],
  description: [{ required: true, message: "请输入描述", trigger: "blur" }],
  diamond: [{ required: true, message: "请输入奖励钻石", trigger: "blur" }],
  go_name: [
    { required: true, message: "请输入跳转app页面名字", trigger: "blur" },
  ],
  go_type: [{ required: true, message: "请选择跳转类型", trigger: "blur" }],
  url: [{ required: true, message: "请输入跳转h5链接", trigger: "blur" }],
};

// 提交
const submit = (dialogForm) => {
  dialogFormRef.value
    .validate()
    .then(async () => {
      try {
        emits("submitForm", dialogForm);
      } catch (error) {
        console.log(error);
      }
    })
    .catch((error) => {
      console.log(error);
    });
};
</script>
